package foxmob.mooc;
import java.sql.*;
import org.jooq.*;
import org.jooq.impl.DSL;

/**
 *
 * @author liyusen
 */
public class DbAccess {
    static String userName, password,url;
    public  static void init(){
         userName = AppCfg.sDbUser;
         password = AppCfg.sDbPwd;
         url = String.format("jdbc:postgresql://%s:%s/%s",
                 AppCfg.sDbHost,AppCfg.sDbPort, AppCfg.sDbName);

    }


    static DSLContext FOXDSL=null;
    static Connection CONN = null;
    public static DSLContext getDsl(){

        try  {
            if(FOXDSL!=null && CONN!=null && !CONN.isClosed()){
                return FOXDSL;
            }
            CONN = DriverManager.getConnection(url, userName, password);
            FOXDSL = DSL.using(CONN, SQLDialect.POSTGRES);
            
        } 

        catch (SQLException e) {
            
        }
        return FOXDSL;
    }
    
}
